package com.icloud.cer.rest.msg.filter;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.keepalive.KeepAliveFilter;
import org.apache.mina.filter.keepalive.KeepAliveRequestTimeoutHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.icloud.cer.rest.util.ConnectorManager;

public class KeepAliveRequestTimeoutHandlerImpl implements KeepAliveRequestTimeoutHandler {
	
	private static final Logger log = LoggerFactory.getLogger(KeepAliveRequestTimeoutHandlerImpl.class);
	
	private ConnectorManager connectManager;
	
	public ConnectorManager getConnectManager() {
		return connectManager;
	}

	public void setConnectManager(ConnectorManager connectManager) {
		this.connectManager = connectManager;
	}
	@Override
	public void keepAliveRequestTimedOut(KeepAliveFilter filter, IoSession session) throws Exception {
		log.warn("heartbeat time out!");
		connectManager.removeClient(session.getId());
		connectManager.removeSession(session.getId());
		log.info("client count: " + connectManager.getClientCount());
	}

}
